/**
 * file
 */
package com.tdkj.action.front.member.seller.shop;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.opensymphony.xwork2.ActionContext;
import com.tdkj.action.BaseAction;
import com.tdkj.model.shop.BeanShopNotice;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.shop.IBeanShopNoticeService;
import com.tdkj.util.PublicConfing;

public class ShopNoticeAction extends BaseAction {

	
	private Long id;
	private String title;
	private String content;
	private Date publishTime;
	private Long userId ;
	
	private BeanShopNotice notice;
	
	private List<BeanShopNotice> notices;
	
	private IBeanShopNoticeService shopNoticeService;
	
	@Override
	public String execute() {
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		userId = user.getId();
		
		String title = this.getQueryInfo().get("title");
		String hql = " from " + BeanShopNotice.class.getName() + " as bean where 1=1 ";
		hql = hql + " and bean.user.id='"+user.getId()+"' ";
		if(title!=null && !"".equals(title)){
			hql = hql + " and bean.title like '%"+title+"%' ";
		}
		hql = hql + " order by bean.publishTime";
		Query query = this.createQuery(hql);
		this.queryByPage(query, "shopNoticeAction.action", 10);
		
		return "success";
	}
	
	public String add() {
		BeanUser user  = (BeanUser)ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		userId = user.getId();
		id = shopNoticeService.add(title, content, userId).getId();
		return edit();
	}
	
	public String edit() {
		notice = shopNoticeService.findById(id, BeanShopNotice.class);
		return "edit";
	}
	
	public String update() {
		shopNoticeService.update(id, title, content, userId);
		return edit();
	}
	
	public String delete() {
		shopNoticeService.delete(id, BeanShopNotice.class);
		return execute();
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @param content the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * @return the publishTime
	 */
	public Date getPublishTime() {
		return publishTime;
	}

	/**
	 * @param publishTime the publishTime to set
	 */
	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}

	/**
	 * @return the userId
	 */
	public Long getUserId() {
		return userId;
	}

	/**
	 * @param userId the userId to set
	 */
	public void setUserId(Long userId) {
		this.userId = userId;
	}

	/**
	 * @return the notice
	 */
	public BeanShopNotice getNotice() {
		return notice;
	}

	/**
	 * @param notice the notice to set
	 */
	public void setNotice(BeanShopNotice notice) {
		this.notice = notice;
	}

	/**
	 * @return the notices
	 */
	public List<BeanShopNotice> getNotices() {
		return notices;
	}

	/**
	 * @param notices the notices to set
	 */
	public void setNotices(List<BeanShopNotice> notices) {
		this.notices = notices;
	}

	/**
	 * @param shopNoticeService the shopNoticeService to set
	 */
	@Resource
	public void setShopNoticeService(IBeanShopNoticeService shopNoticeService) {
		this.shopNoticeService = shopNoticeService;
	}

	
}
